package com.xqc.provider.service.impl;

import com.xqc.provider.mapstruct.UserMapStruct;
import com.xqc.provider.service.UserService;
import com.xqc.provider.service.external.LeaveExternalFacade;
import com.xqc.dao.mapper.UserMapper;
import com.xqc.dao.model.UserModel;
import com.xqc.api.response.UserResponse;
import io.seata.spring.annotation.GlobalTransactional;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserMapper userMapper;

    @Autowired
    private LeaveExternalFacade leaveExternalFacade;

    @Override
    public List<UserResponse> queryAll() {
        return UserMapStruct.INSTANCE.copyModelToRes(this.userMapper.selectList(null));
    }

    @Override
    @GlobalTransactional
    public boolean insert() {
        UserModel userModel = new UserModel();
        userModel.setName("w2");
        this.userMapper.insert(userModel);
        System.out.println("kaishi............");
        this.leaveExternalFacade.startLeave();
        return true;
    }


}
